package com.pow.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.pow.entity.Role;
@Entity
@Table(name="users")
public class User {

	@Id	
	private String id;//用户id 用uuid生成
	private String loginName;//登录名
	private String password;//登录密码
	private String isLockout;//是否锁定
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private String lastLoginTime;//上次登陆时间
	private Integer psdWrongTime;//密码错误次数
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private String lockTime;//锁定时间
	private String protectEMail;//密保邮箱
	private String protectMTel;//密保手机
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private String createTime;//账户创立时间
	@ManyToMany(fetch=FetchType.EAGER) //多对多关系 
	 @JoinTable(name="user_role_tb", //指定第三张中间表名称
	 //本表主键 roleId 与第三张中间表 user_role_tb 的外键 user_role_tb_role_id 对应.本表与中间表的外键对应关系
	 joinColumns={@JoinColumn(name="user_role_tb_user_id")}, //另一张表与中间表的外键的对应关系
	 inverseJoinColumns={@JoinColumn(name="user_role_tb_role_id")})
	@NotFound(action = NotFoundAction.IGNORE) //NotFound : 意思是找不到引用的外键数据时忽略，NotFound 默认是 exception
	private List<Role> roles;
	public User(String id, String loginName, String password, String isLockout, String lastLoginTime,
			Integer psdWrongTime, String lockTime, String protectEMail, String protectMTel, String createTime,
			List<com.pow.entity.Role> roles) {
		super();
		this.id = id;
		this.loginName = loginName;
		this.password = password;
		this.isLockout = isLockout;
		this.lastLoginTime = lastLoginTime;
		this.psdWrongTime = psdWrongTime;
		this.lockTime = lockTime;
		this.protectEMail = protectEMail;
		this.protectMTel = protectMTel;
		this.createTime = createTime;
		this.roles = roles;
	}
	public User() {
		super();
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", loginName=" + loginName + ", password=" + password + ", isLockout=" + isLockout
				+ ", lastLoginTime=" + lastLoginTime + ", psdWrongTime=" + psdWrongTime + ", lockTime=" + lockTime
				+ ", protectEMail=" + protectEMail + ", protectMTel=" + protectMTel + ", createTime=" + createTime
				+ ", roles=" + roles + "]";
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getIsLockout() {
		return isLockout;
	}
	public void setIsLockout(String isLockout) {
		this.isLockout = isLockout;
	}
	public String getLastLoginTime() {
		return lastLoginTime;
	}
	public void setLastLoginTime(String lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}
	public Integer getPsdWrongTime() {
		return psdWrongTime;
	}
	public void setPsdWrongTime(Integer psdWrongTime) {
		this.psdWrongTime = psdWrongTime;
	}
	public String getLockTime() {
		return lockTime;
	}
	public void setLockTime(String lockTime) {
		this.lockTime = lockTime;
	}
	public String getProtectEMail() {
		return protectEMail;
	}
	public void setProtectEMail(String protectEMail) {
		this.protectEMail = protectEMail;
	}
	public String getProtectMTel() {
		return protectMTel;
	}
	public void setProtectMTel(String protectMTel) {
		this.protectMTel = protectMTel;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	
	
	
}
